// 3.10 导入 http 文件
import http from "./http";

// 3.11 发送请求，去到 src 文件夹里面新建 views 文件夹新建 Login 文件夹新建 Login.vue，去到该文件
// export const ApiLogin = (params: any) => http.post('/admin/login', params)

// 5.2这里加上 params 类型约束,然后去到 views 文件夹的 Login文件夹里面的 Login.vue
// export const ApiLogin = (params: ILoginParams) => http.post('/admin/login', params)

// 5.5约束接口返回值，用于.then后面可以点出来
// 5.6因为每个都要写 : Promise<MyResponse<string>> ，所以就去全局 api.d.ts
// export const ApiLogin = (params: ILoginParams): Promise<MyResponse<string>> => http.post('/admin/login', params)

// 5.8使用类型别名
// 5.9因为 data 里面有两个 token. tokenHead，然后要去 api.d.ts
// export const ApiLogin = (params: ILoginParams): RSP<string> => http.post('/admin/login', params)

// 5.11返回值进行类型约束

export const ApiLogin = (params: ILoginParams): RSP<ILoginResponse> =>
  http.post("/admin/login", params);
// UmsAdminController后台用户管理 / 登录以后返回token

// 9.10 UmsAdminController后台用户管理 / 获取当前登录用户信息
// 9.11 因为这个接口，需要携带 token，所以我们需要去到 http.ts 请求拦截器里面获取 token
// export const ApiCurrentInfo = (): RSP<any> => http.get('/admin/info');

// 9.34将any约束改为我们定义的泛型
// 9.35然后回去 components 文件夹里面的 AsideMenu 文件夹里面的 index.vue
export const ApiCurrentInfo = (): RSP<IUserInfoModel> =>
  http.get("/admin/info");

// 18.4请求权限--用户列表 里面的数据， /admin/list 根据用户名或姓名分页获取用户列表
// 18.5因为需要携带 keyword跟 pageNum 和 pageSize，所以我们要携带 params 参数，get 携带参数需要 {params} ,先约束 params 类型为 any
// 18.6通过接口文档可以查看这三个参数的类型
// 18.7去到types文件夹里面的 api.d.ts
// export const ApiGetUserList = (params: any) => http.get('/admin/list', {params})
// 18.10约束 IQueryUserListParams 到携带参数类型
// 18.11去到 src 文件夹里面的 views 文件夹里面的 ums 文件夹里面的 admin.vue
// export const ApiGetUserList = (params: IQueryUserListParams) => http.get('/admin/list', { params })
// 18.19约束接口返回的数据类型
// 18.29去到 views 文件夹里面的 ums文件夹 里面的 admin.vue
// export const ApiGetUserList = (params: IQueryUserListParams): RSP<IUserListResponse> => http.get('/admin/list', { params })

// 20.33携带 config
// 20.34去到 admin.vue
// export const ApiGetUserList = (params: IQueryUserListParams,config?: any): RSP<IUserListResponse> => http.get('/admin/list', { params, cancelToken: config.cancelToken  })

// 27.58这里的接口类型要改成规定好是哪个接口类型,因为这里我们是用一个泛型去约束的,这样子接口类型约束可以复用
// 27.59去到 types 文件夹里面的 api.ts.ts
export const ApiGetUserList = (params: IQueryUserListParams, config?: any): RSP<IUserListResponse<IUserListModel>> => http.get('/admin/list', { params, cancelToken: config.cancelToken })

// 19.8发送修改账号启用禁用方法，/updateStatus/{id}   修改帐号状态
// 19.9先用any定义传参进去的类型，然后查看接口文档需要携带的id和status的类型，去到 types 文件夹里面的 api.d.ts
// export const ApiUpdateStatus = (params: any) => http.post('/updateStatus/{id}', params)
// 19.12约束接口携带参数类型为 IUpdateStatusParams
// export const ApiUpdateStatus = (params: IUpdateStatusParams) => http.post('/updateStatus/{id}', params)
// 19.13需要传入 id 所以 {id} 需要改为动态的 ${id},这里的 id 是从 params 参数里面的 id
// 19.14去到 admin.vue 页面发送请求
// export const ApiUpdateStatus = (params: IUpdateStatusParams) => http.post('/updateStatus/${params.id}', params)

// 19.20注意：有时候后端会要求我们在 请求地址上传递参数，这里在接口文档可以看到 status 需要 query 的形式传入, query 就是 ？id='',约束接口返回的数据为 number
// 19.21去到 http 文件夹里面的 http.ts 文件
export const ApiUpdateStatus = (params: IUpdateStatusParams): RSP<number> =>
  http.post(`/admin/updateStatus/${params.id}?status=${params.status}`);

// 17.12 点击提交然后发送用户注册 /admin/register 用户注册
// export const ApiRegisterUser = (params: any) => http.post('/admin/register', params)
// 17.13用户注册需要携带的数据，跟获取用户数据是同一个类型，
//17.14去到绑定确认按钮事件，去到 editUser.vue 文件
// export const ApiRegisterUser = (params: IUserModel) => http.post('/admin/register', params)
// 17.17这里返回的数据 res.data 的数据跟之前的 IUserListModel 数据是一样的
// 17.18回去 editUser.vue 文件
export const ApiRegisterUser = (params: IUserModel): RSP<IUserListModel> =>
  http.post("/admin/register", params);

// 23.14发送接口点击编辑按钮修改用户信息， /admin/{id}，获取指定用户信息,需要携带id
// 23.15去到 editUser.vue 文件
// export const ApiqueryEditUser = (id: number): RSP<any> => http(`/admin/${id}`)
// 23.22约束接口返回的数据结果，这个数据结果是跟 IUserListModel 获取用户列表信息是一样接口类型
// 23.23去到 editUser.vue,这里我们要写上 id
export const ApiqueryEditUser = (id: number): RSP<IUserListModel> =>
  http(`/admin/${id}`);

// 23.32发送接口数据 /admin/update/{id}，修改指定用户信息
// export const ApiUpdateUserInfo = (params: any): RSP<any> => http.post(`/admin/update/${params.id}`, params)
// 23.33因为这里携带的参数需要由 admin 和 id，这里的 admin 是跟 IUserListModel 类型一样的
// 23.34去到 editUser.vue 文件
// export const ApiUpdateUserInfo = (params: IUserListModel): RSP<any> => http.post(`/admin/update/${params.id}`, params)
// 23.37这里后端返回数据约束的类型为 number
// 23.38去到 editUser.vue 文件
export const ApiUpdateUserInfo = (params: IUserListModel): RSP<number> =>
  http.post(`/admin/update/${params.id}`, params);
// 25.21获取所有角色接口 --- 后台用户角色管理/ /role/listAll,获取所有角色,先用any约束接口返回值
// 25.22去到 allocRole.vue 文件
// export const ApiGetListAll = (): RSP<any> =>http.get('/role/listAll')
// 25.27这里定义接口返回的数据类型是 IRoleModel 的数组
// 25.28去到 allocRole.vue 文件
export const ApiGetListAll = (): RSP<IRoleModel[]> => http.get("/role/listAll");

// 25.33发送接口请求 --- 后台用户管理/ /admin/role/{adminId}，获取指定用户的角色,需要携带 amindId 是 integer 整数类型
// 25.34去到 allocRole.vue 发送请求
// export const ApiCurrentRolePlay = (adminId: number): RSP<any> => http.get(`/admin/role/${adminId}`)
// 25.42约束后端返回的数据类型,去到 allocRole.vue
export const ApiCurrentRolePlay = (adminId: number): RSP<IRoleModel[]> =>
  http.get(`/admin/role/${adminId}`);

// 25.52发送设置用户权限的接口,/admin/role/update给用户分配角色
// export const ApiUpdateRolePlay = (params: any) => http.post('/admin/role/update', params)
// 25.53去到 types 文件夹里面约束 api.d.ts 传参 params 的类型
// export const ApiUpdateRolePlay = (params: IUpdateRolePlayParams) => http.post('/admin/role/update', params)
// 25.56接口文档要求是 query 传参
// 25.57去到 allocRole.vue 发送请求
// export const ApiUpdateRolePlay = (params: IUpdateRolePlayParams) => http.post(`/admin/role/update?adminId=${params.adminId}&roleIds=${params.roleIds}`, params)
// 25.63约束接口的数据类型,自己最好转换一下拼接 join
// 25.64去到 allocRole.vue
export const ApiUpdateRolePlay = (params: IUpdateRolePlayParams): RSP<number> =>
  http.post(
    `/admin/role/update?adminId=${params.adminId}&roleIds=${params.roleIds.join(
      ","
    )}`
  );

// 27.4发送请求获取 权限 -- 角色列表 ，/role/list,根据角色名称分页获取角色列表
// 27.5约束传参的类型跟接口返回的类型为 any
// 27.6去到 hooks 文件夹的 useTable.ts
// export const ApiGetRoleList = (params: any): RSP<any> => http.get('/role/list', {params})
// 27.62约束接口返回的数据类型,以及传参的类型
// 27.63去到 role.vue
export const ApiGetRoleList = (
  params: IQueryUserListParams
): RSP<IUserListResponse<IRoleModel>> => http.get("/role/list", { params });

// 28.4发送接口,/menu/treeList,树形结构返回所有菜单列表
// export const ApiGetAllMenu = (): RSP<any> => http.get('/menu/treeList')
// 28.16这里约束后端返回的数据
export const ApiGetAllMenu = (): RSP<IMenuModelWithChildren[]> => http.get('/menu/treeList')


// 28.5发送接口,/role/listMenu/{roleId},获取角色相关菜单
// 28.6去到 allocMenu.vue 文件里面
// export const ApiGetRoleListMenu = (roleId: number): RSP<any> => http.get(`/role/listMenu/${roleId}`)
// 28.17这里约束后端返回的数据,去到 allocMenu.vue
export const ApiGetRoleListMenu = (roleId: number): RSP<IMenuModel[]> =>
  http.get(`/role/listMenu/${roleId}`);

// 28.39 /role/allocMenu,给角色分配菜单 query传参
// 28.40去到 types 文件夹里面的 api.d.ts
// export const ApiallocChangeMenu = (params: any) => http.post(`/role/allocMenu?roleId=${params.roleId}&menuIds=${params.menuIds.join(',')}`)
// 28.44约束传参的类型,去到 allocMenu.vue 文件
export const ApiallocChangeMenu = (params: IAlocRoleMenuParams): RSP<any> =>
  http.post(
    `/role/allocMenu?roleId=${params.roleId}&menuIds=${params.menuIds.join(
      ","
    )}`
  );

// 29.2 获取查询所有后台资源,后台资源管理---/resource/listAll 查询所有后台资源
// export const ApiGetResourceListAll = ():RSP<IResourceModel[]> => http.get(`/resource/listAll`)
// 29.14对接口返回的类型做约束
export const ApiGetResourceListAll = (): RSP<IResourceModel[]> => http.get(`/resource/listAll`)

// 29.3 获取角色相关资源，后台用户角色管理---/ role / listResource / { roleId }，获取角色相关资源
// 29.4去到 allocResource.vue 里面
// export const ApiGetRoleListResource = (roleId: number) => http.get(`/role/listResource/${roleId}`)
// 29.15对接口返回的类型做约束，这里的数据也是一样的
export const ApiGetRoleListResource = (roleId: number):  RSP<IResourceModel[]> => http.get(`/role/listResource/${roleId}`)

// 29.16获取查询所有后台资源分类，后台资源分类管理---/resourceCategory/listAll,查询所有后台资源分类
// 29.17去到 allocResource.vue 文件
// export const ApiGetResourceCategory = ():RSP<any> => http.get(`/resourceCategory/listAll`)
// 29.23对接口返回的数据做类型约束
// 29.24去到 allocResource.vue 文件
export const ApiGetResourceCategory = (): RSP<IResourceCategoryModel[]> => http.get(`/resourceCategory/listAll`)

// 29.93发送接口请求,后台用户角色管理--- /role/allocResource,给角色分配资源 query传参
// 29.94去 types 文件夹里面 api.d.ts
// export const ApiChangeAllocResource = (params: any): RSP<any> => http.post(`/role/allocResource?resourceIds=${resourceIds}&roleId=${roleId.join(',')}`, params)
// 29.96定义传递参数的类型,去到 allocResource.vue
export const ApiChangeAllocResource = (
  params: IChangeAllocResourceParams
): RSP<any> =>
  http.post(
    `/role/allocResource?resourceIds=${params.resourceIds}&roleId=${params.roleId}`,
    params
  );

// 30.42请求 echarts 数据，这个因为接口文档没有提供，所以去到源网站找到请求 URL, http://kumanxuan1.f3322.net:8360/admin/stat,因为这里请求的 baseUrl 是不一样的，但是如果我们请求中自己携带的url是不会跟 baseUrl 冲突的
// 30.43去到 Echarts.vue 文件，发送接口请求
// export const ApiGetEcharts = (): RSP<any> => http.get(`http://kumanxuan1.f3322.net:8360/admin/stat`)
// 30.48约束接口返回的数据类型,去到 Echarts.vue 文件
export const ApiGetEcharts = (): RSP<IEchartsModel> => http.get(`http://kumanxuan1.f3322.net:8360/admin/stat`)

// 获取菜单列表  
export const ApiGetMenuList = (params: IListParams): RSP<IUserListResponse<IAddMenuModel>> => http.get(`/menu/list/${params.parentId}`, { params: { pageNum: params.pageNum, pageSize: params.pageSize } })

// 菜单列表是否显示
export const ApiUpdateHidden = (params: IMenuModel): RSP<number> => http.post(`/menu/updateHidden/${params.id}?hidden=${params.hidden}`, params)
// 添加菜单 /menu/create

export const ApiCreateMenu = (params: IAddMenuModel): RSP<IAddMenuModel> => http.post('/menu/create', params)

// 根据优惠券名称和类型分页获取优惠券列表
// export const ApiGetCouponList = (params: IGetCouponList): RSP<ICouponListResponse<ICouponListModel>> => http.get('/coupon/list', { params: { pageNum: params.pageNum, pageSize: params.pageSize } })
export const ApiGetCouponList = (params: IGetCouponList): RSP<ICouponListResponse<ICouponListModel>> => http.get(`/coupon/list?name=${params.name}&pageNum=${params.pageNum}&pageSize=${params.pageSize}&type=${params.type}`)
// 优惠券领取  /couponHistory/list
export const ApiCouponHistoryList = (params: IGetCouponHistoryList): RSP<any> => http.get(`/couponHistory/list?orderSn=${params.orderSn}&pageNum=${params.pageNum}&pageSize=${params.pageSize}&useStatus=${params.useStatus}`)
//  获取单个优惠券的详细信息 /coupon/{id}
// export const ApiGetCouponId = (couponId: number): RSP<IMenuModel[]> => http.get(`/coupon/${couponId}`)
export const ApiGetCouponId = (id: number): RSP<IGetCouponIdModel[]> => http.get(`/coupon/${id}`)

// 添加优惠券 /coupon/create
export const ApiAddCoupon = (params: any): RSP<any> => http.post('/coupon/create', params)

//删除优惠券 /coupon/delete/{id}
export const ApiDeleteCouponId = (id: number): RSP<any> => http.post(`/coupon/delete/${id}`)

// 修改优惠券  /update/{id}
export const ApiUpdateCoupon = (params: any): RSP<any> => http.post(`/coupon/update/${params.id}`, params)

//  查询所有一级分类及子分类 /productCategory/list/withChildren
export const ApiWithChildren = () => http.get(`/productCategory/list/withChildren`)

// 新品推荐
// 首页新品管理 --- /home/newProduct/list，分页查询首页新品
export const ApiNewProductList = (params: any): RSP<IBrandListResponse<any>> => http.get('/home/newProduct/list', { params })

// 首页新品管理 --- /home/newProduct/update/recommendStatus，批量修改首页新品状态
export const ApiNewProductRecommendStatus = (params: any): RSP<number> => http.post(`/home/newProduct/update/recommendStatus?ids=${params.ids}&recommendStatus=${params.recommendStatus}`)

// 首页新品管理 --- /home/newProduct/delete，批量删除首页新品
export const ApiNewProductDelete = (id: number[] | number): RSP<number> => http.post(`/home/newProduct/delete?ids=${id}`)

// 首页新品管理 --- /home/newProduct/update/sort/{id},修改首页新品排序
export const ApiNewProductUpdateSort = (params: any): RSP<number> => http.post(`/home/newProduct/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`)

// 商品管理 --- /product/list,查询商品
export const ApiProductListThree = (params: any): RSP<any> => http.get(`/product/list`, { params })

// 首页新品管理 --- /home/newProduct/create,添加首页新品
export const ApiNewProductCreate = (params: any): RSP<any> => http.post(`/home/newProduct/create`, params)

// 获取全部品牌列表
export const ApiGetBrandListAll = (): RSP<IBrandListAllModel[]> => http.get(`/brand/listAll`)

// 根据分页获取品牌列表
export const ApiGetBrandList = (params: IQueryUserListParams): RSP<IBrandListResponse<IBrandListAllModel>> => http.get('/brand/list', { params })

// 添加品牌
export const ApiCreateBrand = (params: ICreateBrandParams): RSP<number> => http.post('/brand/create', params)

// 更新品牌
export const ApiUpdateBrand = (params: ICreateBrandParams): RSP<number> => http.post(`/brand/update/${params.id}`, params)

// 根据id查询品牌信息
export const ApiGetBrandById = (BrandId: number): RSP<ICreateBrandParams> => http.get(`/brand/${BrandId}`)

// 批量更新显示品牌状态
export const ApiUpdateBrandShowStatus = (params: IUpdateBrandShowStatusParams): RSP<number> => http.post(`/brand/update/showStatus?ids=${params.ids}&showStatus=${params.showStatus}`)

// 批量更新厂家制造商状态
export const ApiUpdateBrandFactoryStatus = (params: IUpdateBrandBrandFactoryStatusParams): RSP<number> => http.post(`/brand/update/factoryStatus?ids=${params.ids}&factoryStatus=${params.factoryStatus}`)

// 删除品牌
export const ApiDelBrand = (DelId: number): RSP<object> => http.get(`/brand/delete/${DelId}`)

// 分页查询广告
export const ApiQueryAdvertiseList = (params: IAdvertiseListParams): RSP<IBrandListResponse<IAdvertiseListModel>> => http.get(`/home/advertise/list`, { params })

// 修改上下线状态
export const ApiUpdateAdvertiseStatus = (params: IUpdateAdvertiseStatusParams): RSP<number> => http.post(`/home/advertise/update/status/${params.id}?status=${params.status}`)

// 添加广告
export const ApiCreateAdvertise = (params: IAdvertiseListModel): RSP<number> => http.post(`/home/advertise/create`, params)

// 获取广告详情
export const ApiGetAdvertise = (AdvertiseId: number): RSP<IAdvertiseListModel> => http.get(`/home/advertise/${AdvertiseId}`)

// 修改广告
export const ApiUpdateAdvertise = (params: IAdvertiseListModel): RSP<number> => http.post(`/home/advertise/update/${params.id}`, params)

// 删除广告
export const ApiDelAdvertise = (DelAdvertiseId: number[] | number): RSP<number> => http.post(`/home/advertise/delete?ids=${DelAdvertiseId}`)

// 分页查询推荐品牌
export const ApiQueryBrandList = (params: IQueryBrandParams): RSP<IBrandListResponse<IQueryBrandList>> => http.get('/home/brand/list', { params })

// 添加首页推荐品牌
export const ApiCreateHomeBrand = (params: ICreateHomeBrandParams[]): RSP<number> => http.post('/home/brand/create', params)

// 修改推荐品牌排序
export const ApiUpdateBrandSort = (params: IUpdateBrandSortParams): RSP<number> => http.post(`/home/brand/update/sort/${params.id}?sort=${params.sort}`)

// 批量删除推荐品牌
export const ApiDelHomeBrand = (id: number[] | number): RSP<number> => http.post(`/home/brand/delete?ids=${id}`)

// 批量修改推荐品牌状态
export const ApiUpdateRecommendStatus = (params: UpdateRecommendStatusParams): RSP<number> => http.post(`/home/brand/update/recommendStatus?ids=${params.ids}&recommendStatus=${params.recommendStatus}`)

// 添加首页人气推荐
export const ApiCretateRecommendProduct = (params: any): RSP<any> => http.post('/home/recommendProduct/create', params)

// 批量删除人气推荐
export const ApiDelRecommendProduct = (id: number[] | number): RSP<any> => http.post(`/home/recommendProduct/delete?ids=${id}`)

// 分页查询人气推荐
export const ApiQueryRecommendProduct = (params: any): RSP<any> => http.get('/home/recommendProduct/list', { params })

// 批量修改人气推荐状态
export const ApiUpdateProductRecommendStatus = (params: any): RSP<any> => http.post(`/home/recommendProduct/update/recommendStatus?ids=${params.ids}&recommendStatus=${params.recommendStatus}`)

// 修改人气推荐排序
export const ApiUpdateRecommendProductSort = (params: any): RSP<any> => http.post(`/home/recommendProduct/update/sort/${params.id}?sort=${params.sort}`)

// 商品管理 --- /product/list,查询商品
export const ApiProductList = (params: any): RSP<any> => http.get(`/product/list`, { params })

